#pragma once
#include "EasySize.h"
#include "GraphicArea.h"
#include "ComPortHandler.h"
#include "ComPortConfig.h"
#include "CurveViewer.h"
#include "FileWriter.h"
#include <vector>

class CTinyCaptureDlg : public CDialog
{
public:
	CTinyCaptureDlg(CWnd* pParent = NULL);
	~CTinyCaptureDlg();
	enum { IDD = IDD_TINYCAPTUREL_DIALOG };
//////////////////////////////////////////////////////////////////////////
private:
	DECLARE_EASYSIZE
	void			drawClrRects();
	void			updateDataValues();
	void			setClrRectColor(COLORREF clr, CStatic* clrRect);
	void			initEssentialStuff();
	void			startTimer();
	void			endTimer();
	void			updateCurveViewer(float* dataVal, CurveViewer& curViewer);
	BOOL			dcInitialization();
	BOOL			initToolBar();
	void			moveToolBar();
	void			onRecordData();
	void			onStopRecordData();
	void			startRecordData();
	void			recordDataToFile();
	void			startRecordLog();
	static 
	BOOL CALLBACK	EnumChildProc(HWND hwnd, LPARAM lParam);

public:
	ComPortHandler  mComPortHander;
	GraphicArea		mGraphic;

private:
	//curve viewer
	std::vector<CurveViewer*> mCurveViewerArry;
	//color rects
	std::vector<CStatic*> mClrRects;  
	//data texts
	std::vector<CStatic*> mDataTexts;

	CurveViewer		mGyroViewer;
	CurveViewer		mAccViewer;
	CurveViewer		mMagViewer;
	CurveViewer		mEularViewer;

	//config dialog box
	ComPortConfig	mComPortConfiger;
	CBrush			*m_pBkgBrush;
	int				mOpenGLTimer;
	int				mUIViewTimer;
	HGLRC			hglrc;

	//toolbar
	CToolBar		mToolbar;

	//record button state
	bool			mOnRecord;

	//is recording to file
	bool			mIsRecording;

	//data recorder
	DataFileWriter	mDataFileRecorder;
	
	//log recorder, record com error 
	LogFileWriter	mLogFileRecorder;
//////////////////////////////////////////////////////////////////////////
protected:
	virtual void	DoDataExchange(CDataExchange* pDX);	
protected:
	DECLARE_MESSAGE_MAP()

	HICON m_hIcon;
	virtual BOOL	OnInitDialog();
	afx_msg void	OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void	OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg int		OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void	OnDestroy();
	afx_msg void	OnSize(UINT nType, int cx, int cy);
	afx_msg void	OnSizing(UINT fwSide, LPRECT pRect);
	afx_msg BOOL	OnEraseBkgnd(CDC* pDC);
	afx_msg void	OnConnect();
	afx_msg void	OnDisconnect();
	virtual BOOL	PreTranslateMessage(MSG* pMsg);
	afx_msg void	OnConfigSelcomport();
	afx_msg void	OnTimer(UINT_PTR nIDEvent);
};
